function [bits] = entrop_alg_K(x, alphabet_size)
	
if (~isempty(x))
	mini = min(x);
 	l = length(x);
    num = zeros(1, alphabet_size);
	bits = 0;	
 	
	for i = 1:l
		idx = x(i) - mini + 1;
		p = count_probability2(num(idx), i - 1, alphabet_size);
		if (p > 0 && p~=1)
			bits = bits - log2(p);
		end;
		if (p==1)
             bits = 0;
             return;
        end
		num(idx) = num(idx) + 1;
	end;
	
	bits =  ceil(bits)+1;
   
end
end


function [p] = count_probability2(num, t, alphabet_size)
	p = (2 * num + 1) / (2 * t + alphabet_size);
end
